#!/usr/bin/env python
# -*- coding: utf-8 -*-

# forever mako
'lockhelp module '

__author__ = 'jiahui'

import functools

#------------------------------------------------------------------------------------------------
class lockhelp(object):

    def __init__(self,lock):
        self.lock=lock

    def __enter__(self):
        self.lock.acquire()
        return self

    def __exit__(self, exctype, excvalue, traceback):
        self.lock.release()

def lock(lock):
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args,**kw):
            with lockhelp(lock):
                return func(*args,**kw)
        return wrapper
    return decorator